home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11947 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Non arithmetic integer type.
  5. Date: Wed, 27 Mar 96 20:38:33 GMT
  6. Organization: none
  7. Message-ID: <827959113snz@genesis.demon.co.uk>
  8. References: <4igp11$83a@airdmhor.gen.nz> <4ihfjcINNss6@keats.ugrad.cs.ubc.ca> <4ijp6i$cdu@airdmhor.gen.nz>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4ijp6i$cdu@airdmhor.gen.nz>
  15.            gumboot@airdmhor.gen.nz "Simon Hosie" writes:
  16.  
  17. >In article <4igp11$83a@airdmhor.gen.nz>,
  18. >Simon Hosie <gumboot@airdmhor.gen.nz> wrote:
  19. >>   I've been trying to create a data type that holds an int or intlike chunk
  20. >> of data that is incompatible with any other types (to generate errors if
  21. >> someone assumes that it's the same type as an int).. I've found that
  22. >>
  23. >> typedef struct { int Value; } TypeA;
  24. >> typedef struct { int ValueWithADifferentName; } TypeB;
  25. >> 
  26. >>   makes two compatible types; a variable of TypeA can be assigned to a
  27. >> variable of TypeB without any warnings.. but
  28.  
  29. According to ANSI C these 2 types are incompatible. That means that if you
  30. try to assign a variable of TypeA to a variable of typeB then a conforming
  31. compiler must generate a diagnostic. That's true even if the member names
  32. are the same (within a single translation unit).
  33.  
  34. >Kazimir Kylheku:
  35. >> Your compiler has a gratuitous extension that allows for structural
  36. >> equivalence type checking.
  37. >
  38. >> In standard C, structures with a different tag name are different. 
  39.  
  40. Not, as far as I can tell, if they are in different translation units. Of
  41. course in that case the possibility of assignment between 2 such structures
  42. doesn't exist. However it would certainly be relevant to structures with
  43. external linkage.
  44.  
  45. > Structures
  46. >> declard with _no tag_ are always incompatible with each other and with other
  47. >> structures that have tags.
  48. >  So, do you reckon that if I gave then tags that were _different_ rather
  49. >than absent then they would have another chance at being recognised as
  50. >different?  [Jumps to D*S shell..]  Nope..  Let's try unions..  Nope..  .CPP
  51. >extention..  Got it.
  52. >
  53. >  Is it a C rule or a C++ rule that they be incompatible?
  54.  
  55. It is a C rule. Are you sure that you compiling using options that select
  56. a (claimed) full ANSI compliant mode?
  57.  
  58. -- 
  59. -----------------------------------------
  60. Lawrence Kirby | fred@genesis.demon.co.uk
  61. Wilts, England | 70734.126@compuserve.com
  62. -----------------------------------------
  63.